// $ANTLR 3.0.1 C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g 2008-02-25 15:48:48

package edu.calvin.djs32.cs214.interpreters.frontend;


import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;


import org.antlr.runtime.tree.*;

@SuppressWarnings("all")
public class Hobbes2008Parser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "TUPLE", "NUMBER", "HEXDIGIT", "SIGN", "INTEGER", "WHITESPACE", "COMMENTS", "STRING", "COMMA", "LPAREN", "RPAREN"
    };
    public static final int COMMA=12;
    public static final int INTEGER=8;
    public static final int HEXDIGIT=6;
    public static final int EOF=-1;
    public static final int NUMBER=5;
    public static final int STRING=11;
    public static final int RPAREN=14;
    public static final int LPAREN=13;
    public static final int SIGN=7;
    public static final int TUPLE=4;
    public static final int COMMENTS=10;
    public static final int WHITESPACE=9;

        public Hobbes2008Parser(TokenStream input) {
            super(input);
        }
        
    protected TreeAdaptor adaptor = new CommonTreeAdaptor();

    public void setTreeAdaptor(TreeAdaptor adaptor) {
        this.adaptor = adaptor;
    }
    public TreeAdaptor getTreeAdaptor() {
        return adaptor;
    }

    public String[] getTokenNames() { return tokenNames; }
    public String getGrammarFileName() { return "C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g"; }

     
      protected void mismatch(IntStream input, int ttype, BitSet follow) 
        throws RecognitionException { 
        throw new MismatchedTokenException(ttype, input); 
      } 
      public void recoverFromMismatchedSet(IntStream input, RecognitionException e, BitSet follow) 
        throws RecognitionException { 
        throw e; 
      } 


    public static class program_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start program
    // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:49:1: program : expression EOF ;
    public final program_return program() throws RecognitionException {
        program_return retval = new program_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token EOF2=null;
        expression_return expression1 = null;


        Object EOF2_tree=null;

        try {
            // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:49:8: ( expression EOF )
            // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:49:10: expression EOF
            {
            root_0 = (Object)adaptor.nil();

            pushFollow(FOLLOW_expression_in_program73);
            expression1=expression();
            _fsp--;

            adaptor.addChild(root_0, expression1.getTree());
            EOF2=(Token)input.LT(1);
            match(input,EOF,FOLLOW_EOF_in_program75); 

            }

            retval.stop = input.LT(-1);

                retval.tree = (Object)adaptor.rulePostProcessing(root_0);
                adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
         
          catch (RecognitionException e) { 
            throw e; 
          } 
        finally {
        }
        return retval;
    }
    // $ANTLR end program

    public static class expression_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start expression
    // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:76:1: expression : ( INTEGER | STRING | LPAREN ( expression ( COMMA expression )* )? RPAREN -> ^( TUPLE ( expression )* ) );
    public final expression_return expression() throws RecognitionException {
        expression_return retval = new expression_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token INTEGER3=null;
        Token STRING4=null;
        Token LPAREN5=null;
        Token COMMA7=null;
        Token RPAREN9=null;
        expression_return expression6 = null;

        expression_return expression8 = null;


        Object INTEGER3_tree=null;
        Object STRING4_tree=null;
        Object LPAREN5_tree=null;
        Object COMMA7_tree=null;
        Object RPAREN9_tree=null;
        RewriteRuleTokenStream stream_COMMA=new RewriteRuleTokenStream(adaptor,"token COMMA");
        RewriteRuleTokenStream stream_RPAREN=new RewriteRuleTokenStream(adaptor,"token RPAREN");
        RewriteRuleTokenStream stream_LPAREN=new RewriteRuleTokenStream(adaptor,"token LPAREN");
        RewriteRuleSubtreeStream stream_expression=new RewriteRuleSubtreeStream(adaptor,"rule expression");
        try {
            // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:76:12: ( INTEGER | STRING | LPAREN ( expression ( COMMA expression )* )? RPAREN -> ^( TUPLE ( expression )* ) )
            int alt3=3;
            switch ( input.LA(1) ) {
            case INTEGER:
                {
                alt3=1;
                }
                break;
            case STRING:
                {
                alt3=2;
                }
                break;
            case LPAREN:
                {
                alt3=3;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("76:1: expression : ( INTEGER | STRING | LPAREN ( expression ( COMMA expression )* )? RPAREN -> ^( TUPLE ( expression )* ) );", 3, 0, input);

                throw nvae;
            }

            switch (alt3) {
                case 1 :
                    // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:76:20: INTEGER
                    {
                    root_0 = (Object)adaptor.nil();

                    INTEGER3=(Token)input.LT(1);
                    match(input,INTEGER,FOLLOW_INTEGER_in_expression404); 
                    INTEGER3_tree = (Object)adaptor.create(INTEGER3);
                    adaptor.addChild(root_0, INTEGER3_tree);


                    }
                    break;
                case 2 :
                    // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:76:30: STRING
                    {
                    root_0 = (Object)adaptor.nil();

                    STRING4=(Token)input.LT(1);
                    match(input,STRING,FOLLOW_STRING_in_expression408); 
                    STRING4_tree = (Object)adaptor.create(STRING4);
                    adaptor.addChild(root_0, STRING4_tree);


                    }
                    break;
                case 3 :
                    // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:76:39: LPAREN ( expression ( COMMA expression )* )? RPAREN
                    {
                    LPAREN5=(Token)input.LT(1);
                    match(input,LPAREN,FOLLOW_LPAREN_in_expression412); 
                    stream_LPAREN.add(LPAREN5);

                    // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:76:46: ( expression ( COMMA expression )* )?
                    int alt2=2;
                    int LA2_0 = input.LA(1);

                    if ( (LA2_0==INTEGER||LA2_0==STRING||LA2_0==LPAREN) ) {
                        alt2=1;
                    }
                    switch (alt2) {
                        case 1 :
                            // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:76:47: expression ( COMMA expression )*
                            {
                            pushFollow(FOLLOW_expression_in_expression415);
                            expression6=expression();
                            _fsp--;

                            stream_expression.add(expression6.getTree());
                            // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:76:58: ( COMMA expression )*
                            loop1:
                            do {
                                int alt1=2;
                                int LA1_0 = input.LA(1);

                                if ( (LA1_0==COMMA) ) {
                                    alt1=1;
                                }


                                switch (alt1) {
                            	case 1 :
                            	    // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:76:59: COMMA expression
                            	    {
                            	    COMMA7=(Token)input.LT(1);
                            	    match(input,COMMA,FOLLOW_COMMA_in_expression418); 
                            	    stream_COMMA.add(COMMA7);

                            	    pushFollow(FOLLOW_expression_in_expression420);
                            	    expression8=expression();
                            	    _fsp--;

                            	    stream_expression.add(expression8.getTree());

                            	    }
                            	    break;

                            	default :
                            	    break loop1;
                                }
                            } while (true);


                            }
                            break;

                    }

                    RPAREN9=(Token)input.LT(1);
                    match(input,RPAREN,FOLLOW_RPAREN_in_expression426); 
                    stream_RPAREN.add(RPAREN9);


                    // AST REWRITE
                    // elements: expression
                    // token labels: 
                    // rule labels: retval
                    // token list labels: 
                    // rule list labels: 
                    retval.tree = root_0;
                    RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"token retval",retval!=null?retval.tree:null);

                    root_0 = (Object)adaptor.nil();
                    // 76:87: -> ^( TUPLE ( expression )* )
                    {
                        // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:76:90: ^( TUPLE ( expression )* )
                        {
                        Object root_1 = (Object)adaptor.nil();
                        root_1 = (Object)adaptor.becomeRoot(adaptor.create(TUPLE, "TUPLE"), root_1);

                        // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:76:98: ( expression )*
                        while ( stream_expression.hasNext() ) {
                            adaptor.addChild(root_1, stream_expression.next());

                        }
                        stream_expression.reset();

                        adaptor.addChild(root_0, root_1);
                        }

                    }



                    }
                    break;

            }
            retval.stop = input.LT(-1);

                retval.tree = (Object)adaptor.rulePostProcessing(root_0);
                adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
         
          catch (RecognitionException e) { 
            throw e; 
          } 
        finally {
        }
        return retval;
    }
    // $ANTLR end expression


 

    public static final BitSet FOLLOW_expression_in_program73 = new BitSet(new long[]{0x0000000000000000L});
    public static final BitSet FOLLOW_EOF_in_program75 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_INTEGER_in_expression404 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_STRING_in_expression408 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_LPAREN_in_expression412 = new BitSet(new long[]{0x0000000000006900L});
    public static final BitSet FOLLOW_expression_in_expression415 = new BitSet(new long[]{0x0000000000005000L});
    public static final BitSet FOLLOW_COMMA_in_expression418 = new BitSet(new long[]{0x0000000000002900L});
    public static final BitSet FOLLOW_expression_in_expression420 = new BitSet(new long[]{0x0000000000005000L});
    public static final BitSet FOLLOW_RPAREN_in_expression426 = new BitSet(new long[]{0x0000000000000002L});

}